/**
 * Created by David on 2018/12/5.
 */
const required =()=>{
    throw new Error('Missing parameter');
}
const add=(a=required(),b=required())=>a+b;
add(1,2);
// add(1);
const number=[10,20,30,40];
const doubleOVer50=number.reduce((finalList,num)=>{
    num=num*2;
    if(num>50){
        finalList.push(num);
    }
    return finalList;
},[])
console.log(doubleOVer50);
const isParensBalanced=(str)=>{
    return str.split('').reduce((counter,char)=>{
        if(counter<0){
            return counter;
        }else if(char === '('){
            return ++counter;
        }else if(char === ')'){
            return --counter;
        }else {
            return counter;
        }
    },0)
};
console.log(isParensBalanced('(1)(2)(3)'))
console.log(isParensBalanced('(((1232132)))'))
console.log(isParensBalanced(')(('))
var cars=['BMW','Bens','Bens','Tesla','BMW','ewew'];
var carsObj=cars.reduce((obj,name)=> {
    obj[name]=obj[name]?++obj[name]:1;
})